export const getStorage = (key: string, callback: (result: any) => void) => {
  // @ts-ignore
  chrome.storage.local.get(key, (result) => {
    callback(result[key])
  })
}
export const setStorage = (key: string, value: any) => {
  // @ts-ignore
  chrome.storage.local.set({ [key]: value }, () => {
    console.log(`${key} set to ${value}`)
  })
}


/**
 * 获取数据的函数
 * @param key
 * @returns
 * @ ts-ignore
 */
export const getStorageSync = <T = any>(key: string): Promise<T> => {
  return new Promise((resolve, reject) => {
    // @ts-ignore
    chrome.storage.local.get(key, (result) => {
      // @ts-ignore
      if (chrome.runtime.lastError) {
        // @ts-ignore
        reject(chrome.runtime.lastError);
      } else {
        resolve(result[key] as T);
      }
    });
  });
};

